Lego Sherlock Holmes figure focuses a light beam on a Lego criminal with a small magnifying glass.

Internet of LEGO Things

date and time displayed on EV3 Intelligent Brick

The Internet of Things (IoT) has many devices routinely connected to the internet. You may see your home's lighting, door locks, and appliances all connected to the internet. Why not have the same capability for LEGO inventions? So here I introduce the Internet of LEGO Things, with connection of the EV3 Intelligent Brick to the internet. My first project, shown above, is to have EV3 precisely measure time by hopping on the internet to query a web site for the exact time. I've had several applications that can use such a real-time clock, including data logging of weather variables (see my weather project in "The LEGO Arduino Cookbook") and a spotter for satellites passing overhead (see the free on-line bonus content for my book "High-Tech LEGO Projects" on www.nostarch.com). In these earlier projects, I had to either manually note the time of the beginning of an experiment or use the time data from a GPS sensor. Here's a better way to measure time on an EV3.



The summary of how this real-time EV3 clock works is to use a WiFi Shield on an OpenMV (www.openmv.io) to query a web site. Then the time data is passed from the OpenMV to the EV3 Intelligent Brick by a UART connection. OpenMV is primarily an image sensor, which I've used in several projects in other blog posts. But the OpenMV has much more capability, especially when shields are attached to the OpenMV board. Two such shields are shown below that are used in this project. One shield, on the left side of the photo, is the WiFi Shield that allows internet connection. The second shield is a new development by Anton's MINDSTORMS Hacks (www.antonsmindstorms.com) that allows both power and signal connections between the OpenMV and MINDSTORMS. Shields are installed on the OpenMV by pressing them into headers on the OpenMV circuit boards, as seen in the photo at the top of the page.



an OpenMV and two shields



Python programs control both the EV3 Intelligent Brick and the OpenMV. The advanced functionality of UART communication isn't available on the standard block programming native to EV3, so I setup Python control, which you can find instructions for on www.education.lego.com. The Python code for EV3 is shown below, with steps to read data over UART. In this case I'm pulling in 14 bytes of data that corresponds to year(4 bytes), month(2 bytes), date(2 bytes), hours(2 bytes), minutes(2 bytes), seconds(2 bytes). I display all 14 bytes on a continuous string on the EV3 display in the photo at the top of the page for demonstration purposes. The relevant data for a particular application can be parsed out from this string as needed. The example in the photo would be interpreted as 17:37:38 on August 4, 2021.

EV3 code for reading and displaying date and time


Code for the OpenMV, also in Python, is shown below. The task of this program is to open a WiFi-based internet connection and make a query for the date/time measurement. There's manipulation of the queried data also going on to put it into a date/time format and also left-zero-pad data in the event that the day, hour, minutes, or seconds might be a single byte.

OpenMV code for WiFi internet connection and time measurement